package com.feng.stateAnalysis
{
	import com.feng.ControllerCenter;
	import com.feng.model.KillStealAbility;
	import com.feng.model.Player;

	/**
	 * 抢人头形势分析
	 * @author 风之守望者
	 * 2013-3-31
	 */
	public class KillStealAnalysis extends AnalysisBase
	{
		/** 抢人头可能性 从大到小排列 */
		public var killStealProbabilityList:Vector.<KillStealAbility>;

		/** 被杀可能性 从大到小排列 */
		public var lostHeadProbabilityList:Vector.<KillStealAbility>;

		public function KillStealAnalysis(controllerCenter:ControllerCenter)
		{
			super(controllerCenter);
		}

		override public function analysis():void
		{
			var player:Player;
			var length:int;
			var i:int;
			var playerList:Vector.<Player> = enemyList.concat();
			playerList.push(me);

			//通过攻击力 计算 抢人头可能性
			killStealProbabilityList = new Vector.<KillStealAbility>();
			playerList.sort(function compare(x:Player, y:Player):Number
			{
				return y.speed - x.speed;
			});
			length = playerList.length;

			player = playerList[0];
			var killStealAbility:KillStealAbility = new KillStealAbility();
			killStealAbility.damage = player.attackDamage(avgPlayer) * 2;
			killStealAbility.player = player;
			killStealAbility.attackNum = Math.ceil(player.hp / avgPlayer.attackDamage(player));

			killStealProbabilityList.push(killStealAbility);

			for (i = 1; i < length; i++)
			{
				player = playerList[i];
				killStealAbility = new KillStealAbility();
				killStealAbility.damage = player.attackDamage(avgPlayer);
				killStealAbility.player = player;
				killStealAbility.attackNum = Math.ceil(player.hp / avgPlayer.attackDamage(player));

				killStealProbabilityList.push(killStealAbility);
			}
			killStealProbabilityList.sort(function compare(x:KillStealAbility, y:KillStealAbility):Number
			{
				return y.damage - x.damage;
			});

			lostHeadProbabilityList = killStealProbabilityList.concat();
			lostHeadProbabilityList.sort(function compare(x:KillStealAbility, y:KillStealAbility):Number
			{
				return x.attackNum - y.attackNum;
			});
			
		}
	}
}
